function stringToBigDecimal(value) {
    var bigDecimal = null;
    if (StringUtils.isBlank(value)) {
        return bigDecimal;
    } else {
        value = value.replaceAll(",", "").replaceAll(" ", "");
        bigDecimal = new BigDecimal(value);
        return bigDecimal;
    }
}

function sumBalance(creditCardAllData) {
    var balance = BigDecimal.ZERO;

    for(i=0;i<creditCardAllData.getDeposits().size();i++){
        var creditCardTimeDeposit = creditCardAllData.getDeposits().get(i)
        balance = balance.add(creditCardTimeDeposit.getBalance());
    }
    creditCardAllData.setBalance(balance);
}


//根据中文币种生成英文币种
function convertCurr(transCurrency) {
    if (StringUtils.isNotBlank(transCurrency)) {
        if (transCurrency.contains("RMB") || transCurrency.contains("CNY") || transCurrency.contains("￥") || transCurrency.contains("人民币")) {
            return "CNY";
        } else if (transCurrency.contains("美元")) {
            return "USD";
        }else if (transCurrency.contains("日元")) {
            return "JPY";
        } else if (transCurrency.contains("港币")) {
            return "HKD";
        }else if (transCurrency.contains("加拿大元") || transCurrency.contains("加元")) {
            return "CAD";
        }else if (transCurrency.contains("英镑")) {
            return "GBP";
        }else if (transCurrency.contains("瑞士法郎")) {
            return "CHF";
        }else if (transCurrency.contains("澳大利亚元")|| transCurrency.contains("澳元")) {
            return "AUD";
        }else if (transCurrency.contains("欧元")) {
            return "EUR";
        }else if (transCurrency.contains("新加坡元") ||transCurrency.contains("新元")) {
            return "SGD";
        }else {
            return "OTHER";
        }
    } else {
        return "";
    }
}

function installmentTypeChange(type) {
    if (type.contains("账单")) {
        return "BILL";
    } else if (type.contains("现金")) {
        return "CASH";
    } else if (type.contains("消费") || type.contains("苹果") || type.contains("新兴业")) {
        return "CONSUME";
    } else {
        return "CONSUME";
    }
}


/**
 * @param datestr
 *            要格式化的时间串
 * @param from_format
 *            初始格式(datestr的格式)
 * @param to_format
 *            改变后的格式(想要的格式)
 * @return String格式
 */
function getDateStr( dateStr,  from_format,  to_format) {
    if (dateStr == null) {
        return null
    }
    var date = getDate(dateStr,from_format)
    if (date == null) {
        return ""
    }
    return DateUtil.format(date, to_format);
}

/**
 * @param datestr
 *            要格式化的时间串
 * @param from_format
 *            初始格式(datestr的格式)
 * @param to_format
 *            改变后的格式(想要的格式)
 * @return Date格式
 */
function getDate( dateStr,  from_format) {
    if (dateStr == null) {
        return null
    }
    return DateUtil.parse(dateStr.trim(),from_format)
}
